home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 18 / develop 18 code / OSA Sample / Sources / Application.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-28  |  4.3 KB  |  144 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Application.h
  3.  
  4.     Contains:    TApplication interface
  5.  
  6.     This module derived from the Apple Shared Library Manager
  7.     sample source code supplied with ASLM 1.1 (note that ASLM
  8.     is NOT required for, or used in, this project).
  9.     
  10.     Developed by:    
  11.         
  12.         Paul G Smith (commstalk hq & Full Moon Software, Inc)
  13.         
  14.         you can leave messages at (UK): 0727 844232; (US): 408 253 7199
  15.         BUT I prefer to be contacted by e-mail
  16.         AppleLink:     SMITH.PG
  17.         Internet:     SMITH.PG@applelink.apple.com
  18.         
  19.         "SimpliFace" Sample code to accompany develop article
  20.         on techniques for embedding scripts in applications.
  21.  
  22. */
  23.  
  24. #ifndef __APPLICATION__
  25. #define __APPLICATION__
  26.  
  27. #ifndef __DESK__
  28. #include <Desk.h>
  29. #endif
  30.  
  31. #ifndef __OSUTILS__
  32. #include <OSUtils.h>
  33. #endif
  34.  
  35. #ifndef __APPLEEVENTS__
  36. #include <AppleEvents.h>
  37. #endif
  38.  
  39. #ifndef __SCRIPTOBJECTS__
  40. #include "ScriptableObjects.h"
  41. #endif
  42.  
  43.  
  44. /* this is a type declartion for the qd global so we can access its fields */
  45. /* given a pointer to qd.  For some reason quickdraw doesn't define this type. */
  46. struct qdRec {
  47.     char privates[76];
  48.     long randSeed;
  49.     BitMap screenBits;
  50.     Cursor arrow;
  51.     Pattern dkGray;
  52.     Pattern ltGray;
  53.     Pattern gray;
  54.     Pattern black;
  55.     Pattern white;
  56.     GrafPtr thePort;
  57. };
  58.  
  59. /*
  60.     TApplication:
  61.  
  62.     This is our class which implements a basic Macintosh style program,
  63.     including a MultiFinder-aware event loop. 
  64. */
  65.  
  66. class TApplication : public TScriptableObject
  67. {
  68. public:
  69.     // Our constructor & destructor
  70.     TApplication(Ptr qdPtr);
  71.     TApplication();
  72.     virtual ~TApplication();
  73.  
  74.     // Call this routine to start event loop running
  75.     virtual    void EventLoop();
  76.  
  77.     // Call this routine to run event loop once
  78.     virtual    void InEventLoop();
  79.  
  80. protected:
  81.     // Returns total stack space required in bytes.
  82.     // Returns 0 by default, which tells the initialization code
  83.     // to use the default stack size.
  84.     virtual long StackNeeded();
  85.     // Returns total heap space required in bytes.
  86.     // Returns 0 by default, which tells the initialization code
  87.     // to use whatever heap size is given.
  88.     virtual long HeapNeeded();
  89.  
  90.     static    void AlertUser(short errResID, short errCode);
  91.     static    void BigBadError(short errResID, short errCode);
  92.  
  93.     // Loop control methods you may need to override
  94.     virtual void SetUp();                    // Run before event loop starts
  95.     virtual void CleanUp();                    // run at end of loop
  96.     virtual void ExitLoop();                // to end loop, call this routine
  97.     virtual void DoIdle();                    // idle time handler (blink caret, background tasks)
  98.     virtual void AdjustMenus();                // menu updater routine
  99.     
  100.     virtual Boolean     HandleEvent (EventRecord& theEvent, Boolean& pass);
  101.     // returns true if event was handled
  102.  
  103.     // event handlers you shouldn't need to override in a typical application
  104.     virtual void DoKeyDown();                // also called for autokey events
  105.     virtual void DoActivateEvt();            // handles setup, and calls DoActivate (below)
  106.     virtual void DoUpdateEvt();                // handles setup, and calls DoUpdate (below)
  107.     virtual void DoHighLevelEvent();        // handles Apple Events
  108.     virtual void DoOSEvent();                // Calls DoSuspend, DoResume and DoIdle as apropos
  109.     virtual void DoMouseDown();                // Calls DoContent, DoGrow, DoZoom, etc
  110.     virtual void DoMouseInSysWindow();
  111.     virtual void DoDrag();
  112.     virtual void DoGoAway();                // handles setup, calls TDocument::DoClose
  113.  
  114.     // called by EventLoop and its handlers:
  115.     virtual void AdjustCursor();        // cursor adjust routine, should setup mouseRgn
  116.     virtual void DoMenuCommand(short menuID, short menuItem);
  117.     // called by OSEvent (just calls DoActivate by default, so no clip conversion
  118.     // is done). If you want to convert clipboard, override these routines
  119.     virtual void DoSuspend(Boolean doClipConvert);
  120.     virtual void DoResume(Boolean doClipConvert);
  121.     
  122.     // If you have an app that needs to know about these, override them
  123.     virtual void DoMouseUp();
  124.     virtual void DoDiskEvt();
  125.  
  126.     // Utility routines you need to provide to do MultiFinder stuff
  127.     virtual unsigned long SleepVal();        // how long to sleep in WaitNextEvent
  128.  
  129. private:
  130.     virtual void        InitApplication(Ptr qdPtr);
  131.  
  132. protected:
  133.     // useful variables
  134.     Boolean            fDone;                    // set to true when we are ready to quit
  135.     EventRecord        fTheEvent;                // our event record
  136.     WindowPtr        fWhichWindow;            // currently active window
  137.     Boolean            fInBackground;            // true if our app is suspended
  138.     Boolean            fWantFrontClicks;        // true if we want front clicks
  139.     RgnHandle        fMouseRgn;                // mouse moved region (set it in your DoIdle)
  140.     qdRec*            fqd;                    // pointer to our qd globals
  141. };
  142.  
  143. #endif
  144.